<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<html>
<head>
    <title>Title</title>
</head>
<body style="${pageContext.request.contextPath}/background: url(img/77.jpg)">
<%@include file="index.jsp"%>
<h1 align="center">客户列表</h1>
<form action="${pageContext.request.contextPath}/findByCond" method="post">
    <p style="text-align: center">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        客户姓名:<input type="text" name="username" size="25" value="${param.username}" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        客户性别:
        <input type="radio" name="gender" value="nan" ${param.gender == 'nan'?'checked':''}/>男
        <input type="radio" name="gender" value="nv" ${param.gender == 'nv'?'checked':''}/>女
        <input type="radio" name="gender" value="" ${param.gender == ''?'checked':''}/>无
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        客户类型:
        <select name="type">
            <option value="">无</option>
            <option value="钻石客户"${param.type == '钻石客户'?'selected':''}>钻石客户</option>
            <option value="黄金客户"${param.type == '黄金客户'?'selected':''}>黄金客户</option>
            <option value="青铜客户"${param.type == '青铜客户'?'selected':''}>青铜客户</option>
            <option value="黑铁客户"${param.type == '黑铁客户'?'selected':''}>黑铁客户
            </option>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="submit" value="条件查询"/>
    </p>
</form>

<form action="${pageContext.request.contextPath}/delBatch"  method="post">
    <table border="1" cellspacing="0" cellpadding="15" align="center">
        <tr>
            <th><input type="checkbox"/>全选</th>
            <th>序号</th>
            <th>用户名</th>
            <th>性别</th>
            <th>生日</th>
            <th>手机号</th>
            <th>邮箱</th>
            <th>爱好</th>
            <th>类型</th>
            <th>介绍</th>
            <th>删除</th>
            <th>修改</th>
        </tr>
        <c:forEach items="${requestScope.list}" var="user" varStatus="stat">
        <tr>
            <td class="tt"><input type="checkbox" name="ids"  value="${user.id}"/></td>
            <td>${stat.index+1}</td>
            <td>${user.username}</td>
            <td>${user.gender}</td>
            <td>${user.birthday}</td>
            <td>${user.phonenum}</td>
            <td>${user.email}</td>
            <td>${user.hobby}</td>
            <td>${user.type}</td>
            <td>${user.introduce}</td>
            <td>
                <input type="button"  value="删除" onclick="shanchu(${user.id},this)"/>
            </td>
            <td>
                <input type="button"  value="修改" onclick="xiugai(${user.id})">
            </td>

        </tr>
        </c:forEach>
    </table>
    <p style="text-align: center"><input type="button" onclick="delbacth()" value="批量删除" /></p>
</form>
</body>
</html>
<script src="${pageContext.request.contextPath}/js/jquery-1.12.4.min.js"></script>
<script>
    function shanchu(id,obj){
        var isShan = confirm("确定删除这条数据吗？");
        if(isShan){
            $.ajax({
                url:"${pageContext.request.contextPath}/delUser?id="+id,
                method:"post",
                dataType:"json",
                success:function (result){
                    if(result.code == 200){
                        $(obj).parent().parent().remove();
                    }else {
                        alert(result.msg)
                    }
                }

            })
        }
    }

    function xiugai(id){
        location.href="${pageContext.request.contextPath}/findUserById?id="+id;
    }

    function delbacth(){
        var aaa = $("input[name = 'ids']:checked").length
        if(aaa == 0){
            alert("至少选择一项进行删除！");
            return;
        }

        var isDel = confirm("确定删除多条吗?");
        if(isDel){
            document.forms[1].submit();
        }else{
            location.href="${pageContext.request.contextPath}/list";
        }
    }




</script>
<script>
        $("th input").click(function(){
        $(".tt input").prop("checked",$(this).prop("checked"));
    })
        $(".tt input").click(function(){
        $("th input").prop("checked",$(".tt input").length == $(".tt input:checked").length)
    })
</script>
